<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output method='xml'
				indent="yes"
				omit-xml-declaration="yes"
				doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN"
				doctype-system = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
				/>


<!-- includes -->
<xsl:include href="admin_template.xsl"/>

<!-- parameters -->
<xsl:param name="_user_level"/>
<xsl:param name="_user_logged_in"/>
<xsl:param name="realname"/>
<xsl:param name="lastlogin"/>

<!-- form data + error handling -->
<xsl:param name="_file"/>
<xsl:param name="_file_empty_error"/>

<xsl:param name="_title"/>
<xsl:param name="_title_empty_error"/>

<xsl:param name="_description"/>

<xsl:param name="_date"/>
<xsl:param name="_date_empty_error"/>
<xsl:param name="_date_format_error"/>

<xsl:param name="_tags"/>
<xsl:param name="_tags_format_error"/>

<xsl:param name="_file_uploaded"/>


<xsl:template match="/">
<html>

<!-- html head -->
<xsl:call-template name="admin_head">
<xsl:with-param name="_title">Upload new photo</xsl:with-param>
</xsl:call-template>


<body id="admin_head">
	<xsl:if test="($_user_logged_in)!='false'">
		<!-- menubar -->
		<xsl:call-template name="admin_menu"/>

		<!-- content -->
		<div id="admin_content_div">

						<!-- display form -->
						<xsl:if test="not($_file_uploaded)">

										<div id="admin_form_div">

														<!-- error list -->
														<xsl:if test="$_file_empty_error"><li>Please choose file to upload</li></xsl:if>
														<xsl:if test="$_title_empty_error"><li>Please fill the title field</li></xsl:if>
														<xsl:if test="$_date_empty_error"><li>Please fill the date field</li></xsl:if>
														<xsl:if test="$_date_format_error"><li>Date format: YYYY-MM-DD</li></xsl:if>
														<xsl:if test="$_tags_format_error"><li>Syntax error in the tags field</li></xsl:if>

														<form method="post" enctype="multipart/form-data" action="index.php?op=upload">

																		<!-- file field -->
																		<p id="admin_form_p">
																						<label id="admin_form_label" for="file">File:</label>
																						<input type="file" size="30" name="file" id="admin_form_textfield">
																										<xsl:attribute name="value">
																														<xsl:value-of select="$_file"/>
																										</xsl:attribute>

																										<xsl:if test="$_file_empty_error">
																														<xsl:attribute name="id">admin_form_textfield_error</xsl:attribute>
																										</xsl:if>
																						</input>
																		</p>

																		<!-- title field -->
																		<p id="admin_form_p">
																						<label id="admin_form_label" for="real_name">Title:</label>
																						<input type="text" name="title" id="admin_form_textfield">
																										<xsl:attribute name="value">
																														<xsl:value-of select="$_title"/>
																										</xsl:attribute>

																										<xsl:if test="$_title_empty_error">
																														<xsl:attribute name="id">admin_form_textfield_error</xsl:attribute>
																										</xsl:if>
																						</input>
																		</p>

																		<!-- submit date field -->
																		<p id="admin_form_p">
																						<label id="admin_form_label" for="desc">Date:</label>
																						<input type="text" name="date" id="admin_form_textfield">
																										<xsl:attribute name="value">
																														<xsl:value-of select="$_date"/>
																										</xsl:attribute>

																										<xsl:if test="$_date_empty_error">
																														<xsl:attribute name="id">admin_form_textfield_error</xsl:attribute>
																										</xsl:if>
																										<xsl:if test="$_date_format_error">
																														<xsl:attribute name="id">admin_form_textfield_error</xsl:attribute>
																										</xsl:if>
																						</input>
																						(Format: YYYY-MM-DD)
																		</p>

																		<!-- tags field -->
																		<p id="admin_form_p">
																						<label id="admin_form_label" for="desc">Tags:</label>
																						<input type="text" name="tags" id="admin_form_textfield">
																										<xsl:attribute name="value">
																														<xsl:value-of select="$_tags"/>
																										</xsl:attribute>

																										<xsl:if test="$_tags_format_error">
																														<xsl:attribute name="id">admin_form_textfield_error</xsl:attribute>
																										</xsl:if>
																						</input>
																						(Coma separated list)
																		</p>

																		<!-- description field -->
																		<p id="admin_form_p">
																						<label id="admin_form_label" for="desc">Description:</label>
																						<textarea name="description" id="admin_form_textarea">
																										<xsl:text> </xsl:text>
																						</textarea>
																		</p>


																		<!-- buttons -->
																		<p id="admin_buttons_p">
																						<input type="hidden" name="form_posted" value="posted"/>
																						<input type="submit" value="Upload" id="admin_form_button"/>
																						<input type="reset" value="Reset" id="admin_form_button"/>
																		</p>

														</form>
										</div>
						</xsl:if>

						<xsl:if test="$_file_uploaded">
										<h3>Succesfull upload</h3>
										<strong>Title: </strong><xsl:value-of select="$_title"/><br/>
										<strong>Date: </strong><xsl:value-of select="$_date"/><br/>
										<strong>Tags: </strong><xsl:value-of select="$_tags"/><br/>
										<strong>Description: </strong><xsl:value-of select="$_description"/><br/>
						</xsl:if>
		</div>
	</xsl:if>
	<xsl:if test= "($_user_logged_in)!='true'">
		<h3>Permission forbidden. Not authenticated.</h3>
		<a>
			<xsl:attribute name="href">index.php?op=auth</xsl:attribute><strong>Log in </strong>
		</a>
	</xsl:if>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
